#include<iostream>
using namespace std;
int main()
{
	int t;
	cin >> t;
	while (t--) {
		int n;
		cin >> n;
		//int arr[10][10] = { 0 };
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= n; j++) {
				cout << i * j;
				if (j != n) {
					cout << " ";
				}
			}
			cout << endl;
		}
	}
	return 0;
}